package io.lvdaxian.handwriting.sort.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

class Base implements Serializable {
  private final Integer age;
  
  public Base(Integer age) {
    this.age = age;
  }
  
  public Integer getAge() {
    return this.age;
  }
}

public class Person extends Base {
  private final String name;
  
  public Person(String name, Integer age) {
    super(age);
    this.name = name;
  }
  
  public String getName() {
    return this.name;
  }
  
  @Override
  public String toString() {
    return "Person{" +
        "name='" + name + '\'' +
        '}';
  }
  
  public static void main(String[] args) {
    List<Base> list = new ArrayList<>();
    
    list.add(new Person("lihh1", 20));
    list.add(new Person("lihh2", 12));
    
    list.sort(new AgeComparator());
    
    list.forEach(System.out::println);
  }
  
  static class AgeComparator implements Comparator<Base> {
    @Override
    public int compare(Base o1, Base o2) {
      return o1.getAge() - o2.getAge();
    }
  }
}
